/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ControlEscolar.DAOs;


import com.ControlEscolar.Beans.ExamRequest;
import java.util.ArrayList;

/**
 *
 * @author Listico
 */
public class ExamRequestDAO extends AbstractDAO <ExamRequest> {

    @Override
    public void add(ExamRequest examRequest) throws DAOException {
                String sql = "INSERT INTO examrequest(applicationDate,applicationTime,status,description) values("

              +"\""+ examRequest.getApplicationDate()+"\","
              +"\""+ examRequest.getApplicationTime()+"\","
              +"\""+ examRequest.getStatus()+"\","
              +"\""+ examRequest.getDescription()+"\")";
             System.out.println(sql);
        try {
            connection.executeUpdate(sql);
        } catch (Exception ex) {
            throw new DAOException();
        }
    }

    @Override
    public int delete(String condition) throws DAOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }


    @Override
    public ArrayList<ExamRequest> query() throws DAOException {
         try {
            String sql = "SELECT * FROM examrequest";
            return connection.executeQuery(sql, ExamRequest.class);

        } catch (Exception ex) {
            throw new DAOException();

        }
    }
    public ExamRequest queryStatus(long ID_Request) throws DAOException{

        try {
            String sql = "SELECT * FROM examrequest WHERE status= \"Y\" and ID_Request=" + ID_Request;
            System.out.println(sql);
            ArrayList<ExamRequest> examRequestQuery=connection.executeQuery(sql, ExamRequest.class);
            return getSpecificQuery(examRequestQuery);
        } catch (Exception ex) {
            throw new DAOException();
        }
    }

    @Override
    public int update(ExamRequest examRequest) throws DAOException {
        try {
            String sql = "UPDATE examRequest SET status= \"" + examRequest.getStatus() + "\" WHERE ID_Request= " + examRequest.getID_Request();
            System.out.println(sql);
           connection.executeUpdate(sql);
        } catch (Exception ex) {
            throw new DAOException();
        }
        return 0;
    }

    public ExamRequest queryByID(long ID_Request) throws DAOException{
        try {
            String sql = "SELECT * FROM examrequest WHERE  ID_Request=" + ID_Request;
           ArrayList<ExamRequest> examRequestQuery= connection.executeQuery(sql, ExamRequest.class);
        return getSpecificQuery(examRequestQuery);
        } catch (Exception ex) {
            throw new DAOException();
        }
    }
}